<%@page import="com.winexpress.product.Wine"%>
<%@page import="java.util.List"%>
<%@page import="com.winexpress.product.Category"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.winexpress.util.SessionAttributes"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>wineXpress Search Wine</title>

    </head>
    <body>
        <t:customerNavigation/>

        <div class="header">
            <div class="logo_img"><img alt="Site Name" src="/WineXpressClient/resources/images/logo.png"></div>
        </div>

        <form class="navbar-form navbar-right" style="margin-right: 8%" role="search" style="margin-right: 8%" id="search" action="/WineXpressClient/searchManagement/searchResult" method="post">
            <div class="form-group" style="width:50%'">
                <input type="text" class="form-control" name="key" placeholder="Categroy or wine name">
                <input name="search" id="wineSearch" type="hidden" value="search"/>
            </div>
            <button type="submit" class="btn btn-default">Search</button>
        </form>
        <br><br><br><br>
        <%  Boolean isSearchByCatgory = (Boolean) request.getAttribute("isSearchByCatgory");
            if (!isSearchByCatgory) { %>
        <%  List<Category> clist = (List) request.getAttribute("categoryList");%>
        <% if (!clist.isEmpty()) { %>
        <table class="table table-striped" style="width:84%; margin-left:8%">
            <thead>
                <tr  class="info">
                    <th>Category</th>
                    <th> </th>
                </tr>
            </thead>
            <% for (Object o : clist) {
                        Category c = (Category) o;%>
            <tr style="height: 10%">
                <td style="width: 18%; vertical-align: middle;"> <a href="/WineXpressClient/searchManagement/searchResult?category=<%=c.getName()%>"><%=c.getName()%></a> </td>
            </tr>   
            <%}
                } else {%>
            <tr>
            <div class="alert alert-warning"style="width: 80%; margin-left: 10%; margin-right: 10%" >
                Sorry, there are no such categories.<br> 
                Please contact us by enquiries if you need further help.</div>             
        </tr>

        <%}%>
    </tbody > 
</table >
<%}%>

<br><br>

<table class="table table-striped" style="width:84%; margin-left:8%">
    <thead>
        <tr  class="info">
            <th>&nbsp;&nbsp;</th>
            <th><b>Name</b></th>
            <th><b>Category</b></th>
            <th><b>Producer</b></th>
            <th><b>Vintage</b></th>
            <th><b>Volume</b></th>
            <th><b>Price</b></th>
            <th> </th>
        </tr>
    </thead>
    <tbody>
        <%  List<Wine> list = (List) request.getAttribute("wineList");%>
        <% if (!list.isEmpty()) {
                for (Object o : list) {
                    Wine w = (Wine) o;%>
        <tr style="height: 10%">
            <td style="width: 18%; height: 180px;"> <img src="<%=w.getImageUrl()%>" style="height: 100%; margin: auto; alignment-adjust: central"></td>
            <td style="width: 18%; vertical-align: middle;"> <a href="/WineXpressClient/products/productDetail?id=<%=w.getId()%>"> <%=w.getName()%> </a></td>
            <td style="width: 18%; vertical-align: middle;"> <%=w.getCategoryName()%> </td>
            <td style="width: 18%; vertical-align: middle;"> <%=w.getProducer()%> </td>
            <td style="width: 10%; vertical-align: middle;"> <%=w.getVintage()%> </td>
            <td style="width: 10%; vertical-align: middle;"> <%=w.getVolume()%> ml </td>
            <td style="width: 10%; vertical-align: middle;"> $ <%=w.getPrice()%> </td>
        </tr>   
        <%}
        } else {%>
        <tr>
    <div class="alert alert-warning"style="width: 80%; margin-left: 10%; margin-right: 10%" >
        Sorry, there are no such wines.<br> 
        Please contact us by enquiries if you need further help.</div>             
</tr>
<%}%>

</tbody>

</table>

</body>
</html>
